
/****************************************************************************

Force Engine v0.5

Creado: 28/03/08
Clase: Entity3D.cpp
Hecho by: German Battiston AKA Melkor

****************************************************************************/

//---------------------------------------------------------------------------
#include "Entity3D.h"
//---------------------------------------------------------------------------
Entity3D::Entity3D(Graphics &rkGraphics)
:
m_kName(""),
m_kD3DV3Pos(0,0,0),
m_kD3DV3Rot(0,0,0),
m_kD3DV3Scale(1,1,1),
m_pkGraphics(&rkGraphics)
{
	LoadIdentity();
}
//---------------------------------------------------------------------------
Entity3D::~Entity3D()
{
	
}
//---------------------------------------------------------------------------
void Entity3D::Update(float fTimeBetweenFrames)
{

}
//---------------------------------------------------------------------------
void Entity3D::Rotate(D3DXVECTOR3 kD3DV3Rot)
{
	D3DXMATRIX kRotationMatrix;
	m_kD3DV3Rot.x += kD3DV3Rot.x;
	m_kD3DV3Rot.y += kD3DV3Rot.y;
	m_kD3DV3Rot.z += kD3DV3Rot.z;
	D3DXMatrixRotationYawPitchRoll(&kRotationMatrix, kD3DV3Rot.y,kD3DV3Rot.x,kD3DV3Rot.z);
	TransFormByMatrix(&kRotationMatrix);
}
//---------------------------------------------------------------------------
void Entity3D::Scale(D3DXVECTOR3 kD3DV3Scale)
{
	D3DXMATRIX kScalingMatrix;
	m_kD3DV3Scale = kD3DV3Scale;
	D3DXMatrixScaling(&kScalingMatrix, kD3DV3Scale.x, kD3DV3Scale.y, kD3DV3Scale.z);
	// seteo la escala en 1 para escalarla de forma absoluta y no relativa
	m_kMatLocalTransform._11 = 1;
	m_kMatLocalTransform._22 = 1;
	m_kMatLocalTransform._33 = 1;
	m_kMatLocalTransform._44 = 1;
	TransFormByMatrix(&kScalingMatrix);
}
//---------------------------------------------------------------------------
void Entity3D::Translate(D3DXVECTOR3 kD3DV3OffSet)
{
	D3DXMATRIX kTranslationMatrix;
	m_kD3DV3Pos.x += kD3DV3OffSet.x;
	m_kD3DV3Pos.y += kD3DV3OffSet.y;
	m_kD3DV3Pos.z += kD3DV3OffSet.z;
	D3DXMatrixTranslation(&kTranslationMatrix, kD3DV3OffSet.x, kD3DV3OffSet.y, kD3DV3OffSet.z);
	TransFormByMatrix(&kTranslationMatrix);
}
//---------------------------------------------------------------------------
void Entity3D::TranslateX(float fOffSetX)
{
	D3DXMATRIX kTranslationMatrix;
	m_kD3DV3Pos.x += fOffSetX;
	D3DXMatrixTranslation(&kTranslationMatrix, fOffSetX, 0, 0);
	TransFormByMatrix(&kTranslationMatrix);
}
//---------------------------------------------------------------------------
void Entity3D::TranslateY(float fOffSetY)
{
	D3DXMATRIX kTranslationMatrix;
	m_kD3DV3Pos.y += fOffSetY;
	D3DXMatrixTranslation(&kTranslationMatrix, 0, fOffSetY, 0);
	TransFormByMatrix(&kTranslationMatrix);
}
//---------------------------------------------------------------------------
void Entity3D::TranslateZ(float fOffSetZ)
{
	D3DXMATRIX kTranslationMatrix;
	m_kD3DV3Pos.z += fOffSetZ;
	D3DXMatrixTranslation(&m_kMatLocalTransform, 0, 0, fOffSetZ);
	TransFormByMatrix(&kTranslationMatrix);
}
//---------------------------------------------------------------------------
void Entity3D::TransFormByMatrix(D3DXMATRIX * pkD3DXMatrix)
{
	D3DXMatrixMultiply(&m_kMatLocalTransform,&m_kMatLocalTransform,pkD3DXMatrix);
}
//---------------------------------------------------------------------------
void Entity3D::CopyTransform(D3DXMATRIX * pkD3DMatTransform)
{
	memcpy((void*)&m_kMatLocalTransform,(void*)pkD3DMatTransform,sizeof(D3DXMATRIX));
}
//---------------------------------------------------------------------------
D3DXVECTOR3 Entity3D::GetRot()
{
	return m_kD3DV3Rot;
}
//---------------------------------------------------------------------------
D3DXVECTOR3 Entity3D::GetScale()
{
	return m_kD3DV3Scale;
}
//---------------------------------------------------------------------------
D3DXVECTOR3 Entity3D::GetPos()
{
	return m_kD3DV3Pos;
}
//---------------------------------------------------------------------------
D3DXMATRIX Entity3D::GetTransform()
{
	return m_kMatLocalTransform;
}
//---------------------------------------------------------------------------
void Entity3D::SetTransform()
{
	m_pkGraphics->GetDevice()->SetTransform(D3DTS_WORLDMATRIX(0),&m_kMatLocalTransform);
}
//---------------------------------------------------------------------------
void Entity3D::LoadIdentity()
{
	D3DXMatrixIdentity(&m_kMatLocalTransform);
}
//---------------------------------------------------------------------------